package C_Paper;

import java.util.*;

public class C100_8 {
    //成绩表
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String[] score = new String[m];
        for (int i = 0; i < m; i++) {
            score[i] = sc.next();
        }
        List<String[]> student = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String[] x = new String[m+1];
            for (int j = 0; j < m+1; j++) {
                x[j] = sc.next();
            }
            student.add(x);
        }
        String x = sc.next();
        for (int i = 0; i < score.length; i++) {
            if (Objects.equals(x, score[i])) {
                int index = i+1;
                student.sort(Comparator.comparing((String[] a)->a[index]).reversed().thenComparing((String[] a)->a[0]));
                break;
            }
        }
        for (String[] strings : student) {
            System.out.print(strings[0]+" ");
        }
    }
}
